package com.itheima.edu.info.subwaymanager.controller;

import com.itheima.edu.info.subwaymanager.domain.Manager;

import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Scanner;

/**
 * @Author 王加鑫
 * @Date 2021/5/21 21:27
 * @Version 1.0
 */
public class RegisterControllerImpl implements RegisterController {

    private Scanner scanner = new Scanner(System.in);

    private static ArrayList<Manager> managers = new ArrayList<>();


    //注册账号和密码
    @Override
    public void register() {
        System.out.println("欢迎来到注册界面!");
        System.out.println("请输入您要注册账号的工号:");
        String id = scanner.next();
        System.out.println("请输入您要注册账号的姓名:");
        String name = scanner.next();
        System.out.println("请输入您要注册账号的性别:");
        String gender = scanner.next();
        System.out.println("请输入您要注册账号的电话号码:");
        String telephone = scanner.next();
        Manager manager = new Manager(id,name,gender,telephone);
        managers.add(manager);
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream("itheima-edu-info- subwaymanager/managers.txt",true));
            oos.writeObject(managers);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
